package com.eboss.sbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.eboss.sbs.R;
import com.eboss.sbs.enums.EnumConsts;
import com.eboss.sbs.model.RateInfoEntity;
import com.mytools.tool.utils.StringUtil;

import java.util.List;

public class RateInfoListAdapter extends BaseAdapter {
	
	private Context context;
	private List<RateInfoEntity> datas;
	private LayoutInflater inflater;
	private ViewHolder holder = null;

	public RateInfoListAdapter(Context context, List<RateInfoEntity> datas) {
		this.context = context;
		this.datas = datas;
	}

	@Override
	public int getCount() {
		if(datas!=null&&datas.size()>0)return datas.size();
		else return 0;
	}

	@Override
	public RateInfoEntity getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RateInfoEntity data = datas.get(position);
		
		inflater = LayoutInflater.from(context);

		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.listitem_rateinfo, null);
			holder.ll_bg_icon = (LinearLayout) convertView.findViewById(R.id.ll_bg_icon);
			holder.img_type = (ImageView) convertView.findViewById(R.id.img_type);
			holder.tv_overdrawn=(TextView) convertView.findViewById(R.id.tv_overdrawn);
			holder.tv_rate=(TextView) convertView.findViewById(R.id.tv_rate);
			holder.tv_toaccountday=(TextView) convertView.findViewById(R.id.tv_toaccountday);
			holder.tv_paylimit=(TextView) convertView.findViewById(R.id.tv_paylimit);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		try{
			holder.ll_bg_icon.setBackgroundResource(EnumConsts.SqbPayChannel.getByType(data.getType()).getBg_color_id());
			holder.img_type.setBackgroundResource(EnumConsts.SqbPayChannel.getByType(data.getType()).getIcon2_id());
		}catch(Exception e){}
		
		holder.tv_overdrawn.setText(data.getOverDrawn());
		holder.tv_rate.setText(StringUtil.rateShow(data.getRate())+"‰");
		holder.tv_toaccountday.setText(data.getToAccountDay());
		holder.tv_paylimit.setText(data.getPaylimit());
		
		return convertView;
	}

	public final class ViewHolder {
		private LinearLayout ll_bg_icon;
		private ImageView img_type;
		private TextView tv_overdrawn;
		private TextView tv_rate;
		private TextView tv_toaccountday;
		private TextView tv_paylimit;
	}

}
